package com.example.contacts;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

    Context context;
    ArrayList<ContactsModel> contactsList;
    public RecyclerViewAdapter (Context context, ArrayList<ContactsModel> contactsList){
        this.context = context;
        this.contactsList = contactsList;
    }
    @NonNull
    @Override
    public RecyclerViewAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(this.context).inflate(R.layout.item,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerViewAdapter.MyViewHolder holder, int position) {
        holder.textView.setText(contactsList.get(position).getName());
    }

    @Override
    public int getItemCount() {

        return this.contactsList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
       TextView textView;
       public MyViewHolder(@NonNull View itemView) {

           super(itemView);
           textView = itemView.findViewById(R.id.name);
        }

    }
}
